﻿using System;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using Microsoft.Owin.Security;
using SAIM.Models;
using SAIM.Models.BLL;

namespace SAIM.Controllers
{
    [Authorize]
    public class ManageController : Controller
    {
        private SAIMIdentity UserIdentity {
            get { return new SAIMIdentity(User.Identity); }
        }

        public ManageController()
        {
        }

        //
        // GET: /Manage/Index
        public ActionResult Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage = GetStatusMessage(message);

            using (AspNetUsersBLL user = new AspNetUsersBLL(UserIdentity.GetUserId()))
            {
                // Construcción del modelo a ser pasado a la vista de perfil de usuario
                var model = new IndexViewModel
                {
                    HasPassword = true,
                    PhoneNumber = "",
                    Id = user.Value.Id,
                    UserName = user.Value.UserName,
                    Email = user.Value.Email,
                    Profile = user.Value.AspNetProfiles != null ? user.Value.AspNetProfiles.Name : string.Empty
                };
                return View(model);
            }
            
        }

        /// <summary>
        /// Devuelve la cadena de estatus de mensaje de acuerdo al enumerador recibido  
        /// </summary>
        /// <param name="message">Enumerador que indica la cadena a devolver</param>
        /// <returns></returns>
        private string GetStatusMessage(ManageMessageId? message)
        {
            string statusMessage =
                message == ManageMessageId.Error ? "Se ha producido un error."
                : "";

            return statusMessage;
        }

        #region Aplicaciones auxiliares

        public enum ManageMessageId
        {
            Error
        }

        #endregion
    }
}